package cn.kk.communication.controller;
/*
 *@author KK on 2022.11.19 16:09
 */

import cn.kk.communication.entity.Communication;
import cn.kk.communication.service.CommunicationService;
import cn.kk.communication.service.impl.CommunicationServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/getAllServlet")
public class getAllServlet extends HttpServlet {
    CommunicationService communicationService = new CommunicationServiceImpl();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf8");
        try {
            List<Communication> list = communicationService.getAll();
            request.setAttribute("list",list);
            request.getRequestDispatcher("myContacts.jsp").forward(request,response);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
